#!/bin/bash

BASH_NAME=admin-tail-util.sh
SCRIPT_NAME=admin-tail-util.js
LOG_FILE=./admin-tail-util.out.log
ERR_LOG=./admin-tail-util.err.log

MAX_TIMES=3

case "$1" in
  start)
        echo "Starting $SCRIPT_NAME: "
        forever start -o $LOG_FILE -e $ERR_LOG -a --minUptime 1000ms --spinSleepTime 500ms $SCRIPT_NAME
        echo "DONE."
        ;;
  stop)
        echo "Stopping $SCRIPT_NAME: "
        forever stop $SCRIPT_NAME
        echo "DONE."
        ;;
  restart)
        echo "Restarting $SCRIPT_NAME: "
        forever stop $SCRIPT_NAME
        sleep 1
        forever start -o $LOG_FILE -e $ERR_LOG -a --minUptime 1000ms --spinSleepTime 500ms $SCRIPT_NAME
        echo "DONE."
        ;;
  *)
        echo "Usage: $BASH_NAME {start|stop|restart}" >&2
        exit 1
        ;;
esac

exit 0